package com.zbkj.admin.controller.merchant.v2;

import com.zbkj.dal.base.enums.OrderStatusEnums;
import com.zbkj.dal.base.enums.show.EnumShowVO;
import com.zbkj.dal.base.page.CommonPage;
import com.zbkj.dal.base.result.CommonResult;
import com.zbkj.dal.pojo.request.OrderSendRequest;
import com.zbkj.dal.pojo.request.order.merchant.AdminMerchantPurchaseConfirmRequest;
import com.zbkj.dal.pojo.request.order.merchant.AdminMerchantPurchaseOrderQueryRequest;
import com.zbkj.dal.pojo.response.order.merchant.MerchantOrderPurchaseDetailNewResponse;
import com.zbkj.dal.pojo.response.order.merchant.MerchantOrderPurchasePageNewResponse;
import com.zbkj.service.service.order.merchant.AdminMerchantPurchaseOrderV2Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wangzhengyan
 * @date 2024/4/12 2:44 PM
 */
@Api(tags = "商户后台-订单-买入订单")
@RestController
@RequestMapping("api/admin/merchant/order/purchase")
public class MerchantPurchaseOrderV2Controller {

    @Resource
    private AdminMerchantPurchaseOrderV2Service adminMerchantPurchaseOrderV2Service;

    /**
     * 订单状态
     *
     * @return {@link OrderStatusEnums}
     */
    @GetMapping("/order/status")
    @ApiOperation(value = "订单状态列表")
    public CommonResult<List<EnumShowVO<Integer>>> orderStatus() {
        return CommonResult.success(adminMerchantPurchaseOrderV2Service.getOrderStatusList());
    }

    // 订单列表
    @PreAuthorize("hasAuthority('merchant:order:page:list')")
    @ApiOperation(value = "商户端买入订单分页列表") //配合swagger使用
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public CommonResult<CommonPage<MerchantOrderPurchasePageNewResponse>> getList(@RequestBody AdminMerchantPurchaseOrderQueryRequest request) {
        return CommonResult.success(CommonPage.restPage(adminMerchantPurchaseOrderV2Service.getAdminMerchantOrderPurchaseList(request)));
    }

    // 订单详情
//    @PreAuthorize("hasAuthority('merchant:order:detail')")
    @ApiOperation(value = "商户端买入订单详情") //配合swagger使用
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    public CommonResult<MerchantOrderPurchaseDetailNewResponse> getDetail(@RequestParam("orderNo")String orderNo) {
        return CommonResult.success(adminMerchantPurchaseOrderV2Service.getAdminMerchantOrderPurchaseDetail(orderNo));
    }

    // 发货
    @ApiOperation(value = "商户端买入订单发货") //配合swagger使用
    @RequestMapping(value = "/delivery", method = RequestMethod.POST)
    public CommonResult<Boolean> delivery(@RequestBody OrderSendRequest request) {
        return CommonResult.success(adminMerchantPurchaseOrderV2Service.deliveryMerchantPurchaseOrder(request));
    }

    // 确认提货
    @ApiOperation(value = "商户端买入订单确认提货") //配合swagger使用
    @RequestMapping(value = "/confirmDelivery", method = RequestMethod.POST)
    public CommonResult<Boolean> confirmDelivery(@RequestBody AdminMerchantPurchaseConfirmRequest request) {
        return CommonResult.success(adminMerchantPurchaseOrderV2Service.confirmDeliveryMerchantPurchaseOrder(request.getOrderNo(), request.getDeliveryCode()));
    }
}
